<!-- BEGIN PAGE HEADER-->
<style>
    th {
        vertical-align: middle !important;
        line-height: 24px !important;
        text-align: center;
    }

    td {
        text-align: center;
    }

    .alert-danger {
        font-size: 13px;
        padding: 4px 2px;
        border-radius: 4px;
    }
    .image_contain{
        background: rgba(12,12,12,0.2);
        padding: 6px;
        text-align: center;
    }

    .ibox label {
        margin-left: 8px;
        margin-bottom: 8px;
    }
</style>
<?php
$this->load->view('partials/breadcrumb.tpl') ?>

<div class="row" id="parent-page">
    <div class="col-xs-12">
        <div class="panel panel-success">
            <!-- Default panel contents -->
            <div class="panel-heading" style="display: flex;justify-content: space-between">
                <h3 class="panel-title"><font style="vertical-align: inherit;"><font style="vertical-align: inherit;">申请记录详情</font></font>
                </h3>
            </div>

            <div class="panel-body">
                <?= form_open('', Array('class' => 'form-horizontal', 'role' => 'form', 'id' => 'form_edit', 'data-category-id' => $detail->id)) ?>
                <input type="hidden" id="update_time" name="update_time"
                       value="<?= set_value('update_time', $detail->update_time) ?>"/>
                <div class="col-md-6">
                    <table class="table table-hover table-bordered table-striped">
                        <tr>
                            <th class="col-md-1 text-right">申请测评人：</th>
                            <th class="col-md-4"><?= $allReviewsAdmin[$detail->submiter_id] ?></th>

                        </tr>
                        <tr>
                            <th class="col-md-1 text-right">备注：</th>
                            <th class="col-md-4">
                                <textarea name="remark" class="form-control"><?= $detail->remark ?></textarea>
                            </th>
                        </tr>
                        <tr>
                            <th class="col-md-1 text-right">提交时间：</th>
                            <th class="col-md-4"><?= date('Y-m-d H:s', $detail->create_time) ?></th>
                        </tr>
                    </table>
                </div>
                <div class="col-md-12 margin-top-15">
                    <div class="col-md-4 text-center">
                        <?php if ($detail->pay_image): ?>
                            <img class="img-rounded" src="<?= image_url($detail->pay_image) ?>" />
                            <div id="pay_image"></div>
                        <?php else: ?>
                            <div class="form-group">
                                <label class="col-xs-3 control-label">附加图</label>
                                <div class="col-xs-7">
                                    <input type="text" class="form-control" placeholder="在此处粘贴图片" id="pay_image">
                                    <input type="hidden" name="pay_image">
                                </div>
                                <br>
                            </div>
                            <div class="form-group">
                                <div class="col-xs-3"></div>
                                <div class="col-xs-7">
                                    <div class="image_contain" id="image"></div>
                                </div>
                            </div>
                        <?php endif;  ?>

                    </div>
                    <div class="col-md-4 text-center">
                        <?php if ($detail->pay_image_1): ?>
                            <img class="img-rounded" src="<?= image_url($detail->pay_image_1) ?>" />
                            <div id="pay_image_1"></div>
                        <?php else: ?>
                        <div class="form-group">
                            <label class="col-xs-3 control-label">附加图1</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" placeholder="在此处粘贴图片" id="pay_image_1">
                                <input type="hidden" name="pay_image_1">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-3"></div>
                            <div class="col-xs-7">
                                <div class="image_contain" id="image_1"></div>
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>
                    <div class="col-md-4 text-center">
                        <?php if ($detail->pay_image_2): ?>
                            <img class="img-rounded" src="<?= image_url($detail->pay_image_2) ?>" />
                            <div id="pay_image_2"></div>
                        <?php else: ?>
                        <div class="form-group">
                            <label class="col-xs-3 control-label">附加图2</label>
                            <div class="col-xs-7">
                                <input type="text" class="form-control" placeholder="在此处粘贴图片" id="pay_image_2">
                                <input type="hidden" name="pay_image_2">
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-xs-3"></div>
                            <div class="col-xs-7">
                                <div class="image_contain" id="image_2"></div>
                            </div>
                        </div>
                        <?php endif; ?>
                    </div>

                    <script>
                        (function () {
                            var imgReader = function (item) {
                                var blob = item.getAsFile(),
                                    reader = new FileReader();

                                reader.onload = function (e) {
                                    var img = '<img style="width:100%" src="'+e.target.result+'">';
                                    $("input[name='pay_image']").val(e.target.result);
                                    $('#image').html(img);
                                };

                                reader.readAsDataURL(blob);
                            };
                            var imgReader1 = function (item) {
                                var blob = item.getAsFile(),
                                    reader = new FileReader();

                                reader.onload = function (e) {
                                    var img = '<img style="width:100%" src="'+e.target.result+'">';
                                    $("input[name='pay_image_1']").val(e.target.result);
                                    $('#image_1').html(img);
                                };

                                reader.readAsDataURL(blob);
                            };
                            var imgReader2 = function (item) {
                                var blob = item.getAsFile(),
                                    reader = new FileReader();

                                reader.onload = function (e) {
                                    var img = '<img style="width:100%" src="'+e.target.result+'">';
                                    $("input[name='pay_image_2']").val(e.target.result);
                                    $('#image_2').html(img);
                                };

                                reader.readAsDataURL(blob);
                            };

                            document.getElementById('pay_image').addEventListener('paste', function (e) {
                                var clipboardData = e.clipboardData,
                                    i = 0,
                                    items, item, types;

                                if (clipboardData) {
                                    items = clipboardData.items;

                                    if (!items) {
                                        return;
                                    }

                                    item = items[0];
                                    types = clipboardData.types || [];

                                    for (; i < types.length; i++) {
                                        if (types[i] === 'Files') {
                                            item = items[i];
                                            break;
                                        }
                                    }

                                    if (item && item.kind === 'file' && item.type.match(/^image\//i)) {
                                        imgReader(item);
                                    }
                                }
                            });
                            document.getElementById('pay_image_1').addEventListener('paste', function (e) {
                                var clipboardData = e.clipboardData,
                                    i = 0,
                                    items, item, types;

                                if (clipboardData) {
                                    items = clipboardData.items;

                                    if (!items) {
                                        return;
                                    }

                                    item = items[0];
                                    types = clipboardData.types || [];

                                    for (; i < types.length; i++) {
                                        if (types[i] === 'Files') {
                                            item = items[i];
                                            break;
                                        }
                                    }

                                    if (item && item.kind === 'file' && item.type.match(/^image\//i)) {
                                        imgReader1(item);
                                    }
                                }
                            });
                            document.getElementById('pay_image_2').addEventListener('paste', function (e) {
                                var clipboardData = e.clipboardData,
                                    i = 0,
                                    items, item, types;

                                if (clipboardData) {
                                    items = clipboardData.items;

                                    if (!items) {
                                        return;
                                    }

                                    item = items[0];
                                    types = clipboardData.types || [];

                                    for (; i < types.length; i++) {
                                        if (types[i] === 'Files') {
                                            item = items[i];
                                            break;
                                        }
                                    }

                                    if (item && item.kind === 'file' && item.type.match(/^image\//i)) {
                                        imgReader2(item);
                                    }
                                }
                            });
                        })();
                    </script>

                    <div style="padding-left: 5%;" class="col-md-12">
                        <?= edit_form_uploader('pay_image_3', set_uploader('pay_image_3', $detail->pay_image_3), '', 1) ?>
                        <?= edit_form_uploader('pay_image_4', set_uploader('pay_image_4', $detail->pay_image_4), '', 1) ?>
                        <?= edit_form_uploader('pay_image_5', set_uploader('pay_image_5', $detail->pay_image_5), '', 1) ?>
                    </div>

                </div>
                <?php if (in_array($this->_user->role_id, [7, 8])): ?>
                    <?php $this->load->view('partials/submitButtons.tpl') ?>
                <?php endif; ?>
                <?= form_close() ?>
                <!-- Table -->
            </div>
        </div>

    </div>
    <div class="col-xs-12">
        <div class="portlet box red">
            <div class="portlet-title">
                <div class="caption">
                    <i class="fa fa-cogs"></i>本申请所有款项
                </div>
                <div class="tools">
                    <button type="button" class="btn blue" onclick="error_selected()">批量标记不通过</button>
                    <button type="button" class="btn green" onclick="success_selected()">批量标记通过</button>
                    <button type="button" class="btn purple" onclick="iBox()">导出选项</button>
                </div>
            </div>
            <script>
                function iBox() {
                    $('#choose-field').toggle(500, 'swing')
                }
            </script>
            <?php if (in_array($this->_user->role_id, [7, 8]) || $detail->submiter_id == $this->_user->id) : ?>
                <div style="display:none;" class="portlet-body" id="choose-field">
                    <form action="" method="post" id="export_form">
                        <div class="well well-sm" style="margin: 10px 0;">
                            <div class="checkbox" style="margin-bottom: 15px;">
                                <b><i>请选择要导出的字段：</i></b>
                                <label>
                                    <input id="all" type="checkbox">
                                    全选/全不选
                                </label>
                            </div>
                            <div class="checkbox ibox">
                                <label>
                                    <input class="fbox" name="field[]" value="id" type="checkbox">id
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="operator_id" type="checkbox">接单人
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="admin_group_name" type="checkbox">接单人所属组
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="task_id" type="checkbox">所属任务
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="asin" type="checkbox">任务sain
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="product_image" type="checkbox">任务图片
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="comment_link" type="checkbox">评论连接
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="shop_id" type="checkbox">店铺
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="order_no" type="checkbox">订单编号
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="buyer_order_time" type="checkbox">买手下单时间
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="buyer_pay_time" type="checkbox">买手付款时间
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="true_product_price" type="checkbox">购买时商品价格
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="buyer_pay_total" type="checkbox">买手下单支付费用
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="buyer_pay_coin_type" type="checkbox">买家付款币种
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="payment_type" type="checkbox">打款类型
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="pay_method" type="checkbox">付款方式
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="contact" type="checkbox">收款联系方式
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="pay_account" type="checkbox">收款账户
                                </label>

                                <label>
                                    <input class="fbox" checked name="field[]" value="bank" type="checkbox">开户行信息
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="amount" type="checkbox">应付金额
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="coin_type" type="checkbox">应付币种
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="rate_rmb" type="checkbox">对人民币汇率
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="add_image" type="checkbox">凭证
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="add_image_1" type="checkbox">凭证1
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="add_image_2" type="checkbox">凭证2
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="finance_id" type="checkbox">财务处理者
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="status" type="checkbox">状态
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="remark" type="checkbox">备注
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="create_time" type="checkbox">创建时间
                                </label>
                                <label>
                                    <input class="fbox" name="field[]" value="update_time" type="checkbox">更新时间
                                </label>
                                <input type="hidden" name="pay_request_id" value="<?= $detail->id ?>">
                                <input type="hidden" name="file_name" value="pay_operate_<?= $detail->id ?>">
                                <input type="hidden" name="excel_type" value="PayTaskRecordItemExport">
                            </div>
                            <div class="text-right">
                                <button id="export-xls" type="button" class="text-right btn blue-madison">原版导出</button>
                                <button id="export-xls-python" type="button" class="text-right btn red">快速导出</button>
                            </div>
                            <script>
                                $('#export-xls').click(function () {
                                    var data = $('#export_form').serialize();
                                    if (data.indexOf('field') == -1) {
                                        toastr.error('请选择要导出的字段！', '失败');
                                        return false;
                                    } else {
                                        var x = 1;
                                        var y = 1;
                                        $('#process').modal('show');
                                        setInterval(function () {
                                            x += parseFloat(Math.random(0, 1));
                                            var width = x.toFixed(2) + '%';
                                            if (parseInt(x) >= 99) {
                                                x = y / (y + 1) * 100;
                                                y++;
                                            }
                                            $('#show-process').html(width);
                                            $('#show-process').css('width', width)
                                        }, 1000);
                                        $.ajax({
                                            url: '<?=site_url("/common/ExcelExport/excel_export")?>',
                                            data: $('#export_form').serialize(),
                                            method: 'POST',
                                            dataType: 'json',
                                            success: function (output) {
                                                clearInterval();
                                                console.log(output);
                                                // return;
                                                $('#show-process').html('100%');
                                                $('#show-process').css('width', '100%');
                                                $('#process').modal('hide');
                                                toastr.success(output.msg, '成功');
                                                document.location.href = '/' + output.url;
                                            },
                                            fail: function (data) {
                                                toastr.error(data.msg, '失败')
                                            }
                                        })
                                    }
                                });

                                $('#export-xls-python').click(function () {
                                    var data = $('#export_form').serialize();
                                    if (data.indexOf('field') == -1) {
                                        toastr.error('请选择要导出的字段！', '失败');
                                        return false;
                                    } else {
                                        var x = 1;
                                        var y = 1;
                                        $('#process').modal('show');
                                        setInterval(function () {
                                            x += parseFloat(Math.random(0, 1));
                                            var width = x.toFixed(2) + '%';
                                            if (parseInt(x) >= 99) {
                                                x = y / (y + 1) * 100;
                                                y++;
                                            }
                                            $('#show-process').html(width);
                                            $('#show-process').css('width', width)
                                        }, 1000);
                                        $.ajax({
                                            url: '<?=site_url("/common/ExcelExport/python_export")?>',
                                            data: $('#export_form').serialize(),
                                            method: 'POST',
                                            dataType: 'json',
                                            success: function (output) {
                                                clearInterval();
                                                console.log(output);
                                                // return;
                                                $('#show-process').html('100%');
                                                $('#show-process').css('width', '100%');
                                                $('#process').modal('hide');
                                                if(output.status){
                                                    toastr.success(output.msg, '成功');
                                                }else{
                                                    toastr.error(output.msg, '失败');
                                                }
                                                document.location.href = '/' + output.url;
                                            },
                                            fail: function (data) {
                                                toastr.error(data.msg, '失败')
                                            }
                                        })
                                    }
                                });

                                $('#all').click(function () {
                                    if ($(this).prop("checked") == true) {
                                        $(".fbox").prop('checked', true);
                                        $(".fbox").parent('span').addClass('checked');
                                        return;
                                    } else {
                                        $(".fbox").prop('checked', false);
                                        $(".fbox").parent('span').removeClass('checked');
                                        return;
                                    }
                                });
                            </script>
                        </div>
                    </form>
                </div>
            <?php endif; ?>
            <div class="portlet-body">

                <div class="table-scrollable">
                    <table class="table table-hover">
                        <tr>
                            <th width="2%">
                                <label>
                                    <input type="checkbox" id="merge_all">
                                </label>
                            </th>
                            <th class="text-center" width="3%">ID</th>
                            <th class="text-center" width="5%">商品名称</th>
                            <th class="text-center" width="5%">店铺</th>
                            <th class="text-center" width="3%">接单者</th>
                            <th class="text-center" width="7%">买家下单单号</th>
                            <th class="text-center" width="5%">买家实际支付</th>
                            <th class="text-center" width="4%">应付款金额</th>
                            <th class="text-center" width="4%">付款类型</th>
                            <th class="text-center" width="3%">状态</th>
                            <th class="text-center" width="6%">创建时间</th>
                            <th class="text-center" width="6%">打款时间</th>
                            <th class="text-center" width="5%">操作</th>
                        </tr>
                        <?php foreach ($list as $v) { ?>
                            <tr>
                                <td>
                                    <input type="checkbox" class="mbox" name="ceping_ids[]" value="<?= $v->id ?>" title="ID:<?= $v->id ?>">
                                </td>
                                <td><?= $v->id ?></td>
                                <td><?= $v->product_name ?></td>
                                <td><?= IOSS_StaticConfig::getAllShops()[$v->shop_id] ?></td>
                                <td><?= $allReviewsAdmin[$v->operator_id]; ?></td>
                                <td><?= $v->order_no ?></td>
                                <td class="text-center buyer_pay_total"><?= number_format($v->buyer_pay_total, 2, '.', '') ?> (<?=IOSS_StaticConfig::getcoinTypeInfo($v->buyer_pay_coin_type);?>)</td>
                                <td class="text-center buyer_pay_total"><?= number_format($v->amount, 2, '.', '') ?> (<?= IOSS_StaticConfig::getcoinTypeInfo($v->coin_type) ?>)</td>
                                <td class="text-center" ><?= IOSS_StaticConfig::$payTypeArray[$v->payment_type] ?></td>
                                <td class="text-center"><?= MTaskRecordItem::getState($v->status); ?></td>
                                <td><?= date('Y-m-d H:i:s', $v->create_time) ?></td>
                                <td><?= ($v->create_time == $v->update_time && $v->update_time !== 0) ? '' : date('Y-m-d H:i:s', $v->update_time) ?></td>
                                <?php if ($p->read): ?>
                                    <td>
                                        <a href="javascript:ioss_url_modal('<?= site_url('/tasks/taskrecorditem/ajaxViewDetail/' . $v->id) ?>');"
                                           class="btn btn-sm blue ">
                                            <i class="fa fa-play"></i> 查看
                                        </a>
                                    </td>
                                <?php endif; ?>
                            </tr>
                        <?php } ?>
                    </table>
                </div>
                <div class="row">
                    <div class="col-xs-12 text-right">
                        <?= $pagination ?>
                    </div>
                </div>
            </div>
        </div>

    </div>

</div>

<script type="text/javascript">
    $(document).ready(function () {
        $(document).ready(function () {
            $('.img-rounded').zoomify();
        });

        $("input[name='pay_amount']").blur(function () {
            var rate = $("input[name='current_rate_rmb']").val();
            var amount = $(this).val();
            $("input[name='pay_amount']").val(amount);
            console.log(rate + '×' + amount);
            $("input[name='pay_amount_rmb']").val((amount * rate).toFixed(3));
        });

        $("input[name='current_rate_rmb']").blur(function () {
            var rate = $(this).val();
            var amount = $("input[name='pay_amount']").val();
            $("input[name='current_rate_rmb']").val(rate);
            console.log(rate + '×' + amount);
            $("input[name='pay_amount_rmb']").val((amount * rate).toFixed(3));
        });

        $('#edit').click(function () {
            $('#editModal').modal('show');
        });
        //计算页面总金额
        var buyer_pay_total = 0;
        var true_shuadan_amount = 0;
        var commission = 0;
        var intror_commission = 0;
        for (var i = 0; i < $('.buyer_pay_total').length; i++) {
            buyer_pay_total += parseFloat($('.buyer_pay_total').eq(i).html());
        }
        for (var i = 0; i < $('.true_shuadan_amount').length; i++) {
            true_shuadan_amount += parseFloat($('.true_shuadan_amount').eq(i).html());
            console.log(parseFloat($('.true_shuadan_amount').eq(i).html()));
        }
        for (var i = 0; i < $('.commission').length; i++) {
            commission += parseFloat($('.commission').eq(i).html());
        }
        for (var i = 0; i < $('.intror_commission').length; i++) {
            intror_commission += parseFloat($('.intror_commission').eq(i).html());
        }
        $('#buyer_pay_total').html(buyer_pay_total.toFixed(3));
        $('#true_shuadan_amount').html(true_shuadan_amount.toFixed(3));
        $('#commission').html(commission.toFixed(3));
        $('#intror_commission').html(intror_commission.toFixed(3));
        $('#total').html((true_shuadan_amount + commission + intror_commission).toFixed(3));

        AjaxUploader.uploadTempUrl = "<?=site_url('/common/AjaxUpload/upload') . '/'  ?>";
        AjaxUploader.model_init('parent-page');
        AjaxUploader.model_init('editModal');

        $('#merge_all').click(function () {
            if ($(this).prop("checked") == true) {
                $(".mbox").prop('checked', true);
                $(".mbox").parent('span').addClass('checked');
                return;
            } else {
                $(".mbox").prop('checked', false);
                $(".mbox").parent('span').removeClass('checked');
                return;
            }
        });
    });

   //批量标记选中的为异常
   function error_selected(){
       var selected_items = $("input[name='ceping_ids[]']:checked");
       if(selected_items.length == 0){
           alert("要先选择要标记的项！");
           return;
       }
       //console.log($(selected_items).serialize());
       $.ajax({
                url:"<?= site_url('tasks/taskrecorditem/setStatus2') ?>",
                type:'POST',
                data: $(selected_items).serialize(),
                success: function(res){
                    console.log('success:'+res);
                    window.location.reload();
                },
                error:function(res){
                    console.log('error:'+res);
                    window.location.reload();

                }
            });
   }
   //批量标记选中的为异常
   function success_selected(){
       var selected_items = $("input[name='ceping_ids[]']:checked");
       if(selected_items.length == 0){
           alert("要先选择要标记的项！");
           return;
       }
       //console.log($(selected_items).serialize());
       $.ajax({
                url:"<?= site_url('tasks/taskrecorditem/setStatus3') ?>",
                type:'POST',
                data: $(selected_items).serialize(),
                success: function(res){
                    console.log('success:'+res);
                    window.location.reload();

                },
                error:function(res){
                    console.log('error:'+res);
                    window.location.reload();

                }
            });
   }
</script>
